import { sort, prop, ascend } from 'ramda';
export default class Dictionary {
  static convertArray(id, list) {
    try {
      const array = list.reduce((i, c) => {
        if (c.parentId === id) {
          // /^{.*}$/ 匹配 必须以{} 开头结尾，中间任意值
          if (/^{.*}$/.test(c.value)) {
            i.push(JSON.parse(c.value));
          } else {
            i.push(c);
          }
        }
        return i;
      }, []);
      return sort(ascend(prop('value')), array);
    } catch (error) {
      console.error(error);
    }
  }
}
